<?php
abstract class DatabaseTable {
    protected $records;
    protected $conn;
    private $language;

    public function __construct($conn) {
        $this->records=array ();
        $this->conn=$conn;
        $this->language=new Language();
        $this->load();
    }

    public function setLanguage(Language $lang) {
        if ($lang->getId()!=$this->language->getId()) {
            $this->language=$lang;
            $this->records=array ();
            $this->load();
        }
        $this->language=$lang;
    }

    public function getLanguage() {
        return $this->language;
    }

    public function get($id) {
        return $this->records[$id];
    }

    public function getAll() {
        return $this->records;
    }
    protected abstract function load();

    static function mysql_fetch_alias_array($result) {
        if (!($row = mysql_fetch_array($result))) {
            return null;
        }
        
        $assoc = Array();
        $rowCount = mysql_num_fields($result);

        for ($idx = 0; $idx < $rowCount; $idx++) {
            $table = mysql_field_table($result, $idx);
            $field = mysql_field_name($result, $idx);
            $assoc["$table.$field"] = $row[$idx];
        }

        return $assoc;
    }
}
?>
